home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / lib / whereis.pl < prev   
Encoding:
Text File  |  1994-11-22  |  1023 b   |  42 lines

  1. /*  $Id: whereis.pl,v 1.2 1994/11/22 15:10:29 jan Exp $
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Find predicates
  7. */
  8.  
  9. :- module(whereis,
  10.     [ whereis/1
  11.     ]).
  12.  
  13. :- module_transparent
  14.     whereis/1.
  15.  
  16. %    whereis(+Spec)
  17. %    Find predicate definition.
  18.  
  19. whereis(Spec) :-
  20.     '$find_predicate'(Spec, List),
  21.     member(Head, List),
  22.     '$predicate_name'(Head, PredName),
  23.     (   '$defined_predicate'(Head)
  24.     ->  predicate_property(Head, file(File)),
  25.         predicate_property(Head, line_count(Line)),
  26.         format('~t~8|~w is in ~w:~d~n', [PredName, File, Line])
  27.     ;   '$strip_module'(Head, Module, H),
  28.         functor(H, Name, Arity),
  29.         '$find_library'(Module, Name, Arity, _, Lib),
  30.         libname(Lib, LibName),
  31.         format('~t~8|~w is in ~w~n', [PredName, LibName])
  32.     ),
  33.     fail ; true.
  34.  
  35. libname(File, library(LibName)) :-
  36.     findall(LN, ( library_directory(X),
  37.               concat(X, LN, File)),
  38.         [LN0]),
  39.     (concat('/', LN1, LN0) -> true ; LN1 = LN0),
  40.     (concat(LibName, '.pl', LN1) -> true ; LibName = LN1).
  41.     
  42.